package com.micro.util;


import com.mysql.jdbc.Blob;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * Created by Administrator on 2017/3/19.
 */
public class BlobUtil {
    public static String mysqlBlob2str(Object o) {
        if (o == null)
            return null;
        System.out.println(o);
        Blob b = (Blob) o;
        try {
            InputStream in = b.getBinaryStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            byte[] data = new byte[4096];
            int count = -1;

            while ((count = in.read(data, 0, 4096)) != -1)
                out.write(data, 0, count);

            data = null;
            String result = new String(out.toByteArray(), "utf-8");
            return result;
        } catch (Exception e) {
            return null;
        }
    }
}
